package com.eclipse.e20200125_xml_properties_注解.xml;

import java.io.File;
import java.util.List;

import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

public class SAX解析 {
	public static void main(String[] args) throws Exception {
		//通过SAXReader读取文件
		SAXReader reader = new SAXReader();
		//获取document对象
		Document document = reader.read(new File("./src/main/java/com/eclipse/e20200125_xml_properties_注解/xml/config.xml"));

		//获取根元素config
		Element elementRoot = document.getRootElement();

		Element e1 = elementRoot.element("jdbc");
		
		e1.attributeValue("gec");
		
		System.out.println(e1.attributeValue("id"));
		//根元素下所有节点的集合 jdbcs
		List<Element> jdbcs = elementRoot.elements();
		
		
		
		
		
		//遍历所有元素
		jdbcs.forEach((e) -> {
			//元素.attributeValue("属性名称")获取属性
			System.out.println(e.getName() + " " + e.attributeValue("id"));

			List<Element> properties = e.elements();
			//获取单个值
//			System.out.println(properties.get(0).getText());

			properties.forEach((t) -> {
				System.out.println("\t" + t.getName() + ":" + t.getText());
			});
		});

	}
}
